{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据std 缩放 Current_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import joblib\n",
    "from joblib import Parallel,delayed\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def scale_sensors_cur(data_no, csv_nos):\n",
    "    '''\n",
    "    描述：\n",
    "        scale current\n",
    "    '''\n",
    "    input_dir = './sensors_ad/0%d/'%data_no\n",
    "    output_dir = './sensors_scale_cur/0%d/'%data_no\n",
    "    \n",
    "    if not os.path.exists('./sensors_scale_cur'):\n",
    "        os.mkdir('./sensors_scale_cur')\n",
    "    if not os.path.exists('./sensors_scale_cur/0%d'%data_no):\n",
    "        os.mkdir('./sensors_scale_cur/0%d'%data_no)\n",
    "    def basis_func(idx):\n",
    "        sensor = joblib.load(input_dir + '%d.lz4'%idx)\n",
    "        tmp = sensor['Current_1']\n",
    "        sensor['Current_1'] = tmp.values/tmp.std()\n",
    "        joblib.dump(sensor, output_dir + '%d.lz4'%idx)\n",
    "        \n",
    "    Parallel(n_jobs=24, verbose=1)(delayed(basis_func)(i) for i in range(1,csv_nos+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=24)]: Using backend LokyBackend with 24 concurrent workers.\n",
      "[Parallel(n_jobs=24)]: Done  48 out of  48 | elapsed:  1.5min finished\n"
     ]
    }
   ],
   "source": [
    "scale_sensors_cur(1, 48)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=24)]: Using backend LokyBackend with 24 concurrent workers.\n",
      "[Parallel(n_jobs=24)]: Done  48 out of  48 | elapsed:  1.6min finished\n"
     ]
    }
   ],
   "source": [
    "scale_sensors_cur(2, 48)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=24)]: Using backend LokyBackend with 24 concurrent workers.\n",
      "[Parallel(n_jobs=24)]: Done  28 out of  37 | elapsed:   59.1s remaining:   19.0s\n",
      "[Parallel(n_jobs=24)]: Done  37 out of  37 | elapsed:  1.2min finished\n"
     ]
    }
   ],
   "source": [
    "scale_sensors_cur(3, 37)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
